package org.icress.fusion.b2b

import org.icress.fusion.shiro.User
import org.apache.shiro.SecurityUtils


class SalesOrderApprovalService {

    static transactional = true

	def dealer_submit(id){
        //get user
        def currentUser = User.findByUsername(SecurityUtils.getSubject().getPrincipal())
		salesOrderInstance = SalesOrder.get(id)
        salesOrderInstance.status = "待审（办事处）"
        //validate
        salesOrderInstance.validate()
        //save
        salesOrderInstance.save(flush: true)
	}
    
	def dealer_revoke(id){
        //get user
        def currentUser = User.findByUsername(SecurityUtils.getSubject().getPrincipal())
		salesOrderInstance = SalesOrder.get(id)
        salesOrderInstance.status = "草稿"
        //validate
        salesOrderInstance.validate()
        //save
        salesOrderInstance.save(flush: true)
	}
	
	def department_approval(id){
        //get user
        def currentUser = User.findByUsername(SecurityUtils.getSubject().getPrincipal())
		salesOrderInstance = SalesOrder.get(id)
        salesOrderInstance.status = "待审（商务部）"
        //validate
        salesOrderInstance.validate()
        //save
        salesOrderInstance.save(flush: true)
	}
	
	def department_reject(id){
        //get user
        def currentUser = User.findByUsername(SecurityUtils.getSubject().getPrincipal())
		salesOrderInstance = SalesOrder.get(id)
        salesOrderInstance.status = "未通过"
        //validate
        salesOrderInstance.validate()
        //save
        salesOrderInstance.save(flush: true)
	}

}
